<template>
  <div class="app-container">
    <div class="searchBox">
      <el-form :inline="true" :model="search" class="demo-form-inline">
        <el-form-item label="版本名：">
          <el-input v-model="search.name" name="name" placeholder="请输入内容"></el-input>
        </el-form-item>
        <el-form-item label="版本号：">
          <el-input v-model="search.version" name="version" placeholder="请输入内容"></el-input>
        </el-form-item>

        <el-form-item style="margin-top: -2px;">
          <el-button type="primary" @click="searchQuery">查询</el-button>
          <el-button type="info" @click="search = {};searchQuery()">重置</el-button>
        </el-form-item>
      </el-form>
    </div>

    <qm-table
      ref="qmTable"
      :data="query"
      keyProp="versionId"
      menuType="text"
      :formOptions="{ labelWidth: '120px' }"
      :showEdit="false"
      :showAdd="false"
      :showView="false"
      :showOrder="false"
      :isCustomForm="true"
      formRefs="form1"
    >
      <qm-table-column field="operateType" sortable="true" :renderFunc="renderOperateType">操作类型</qm-table-column>
      <qm-table-column field="name" sortable="true">版本名</qm-table-column>
      <qm-table-column field="version" sortable="true">版本号</qm-table-column>
      <qm-table-column field="memo" sortable="true">备注</qm-table-column>
      <qm-table-column field="createdUserName" sortable="true">创建人</qm-table-column>
      <qm-table-column field="createdDate" sortable="true" width="160px">创建时间</qm-table-column>

      <template v-slot:toolbar>
        <el-button @click="exportVersion">导出当前版本</el-button>
        <el-button @click="publishVisible = true;">发布版本</el-button>
      </template>
    </qm-table>

    <vxe-modal ref="xModal" v-model="publishVisible" width="800px" showFooter destroy-on-close>
      <create ref="create" @done="publishVisible = false"></create>

      <template #footer>
        <el-button @click="publish">上传</el-button>
      </template>
    </vxe-modal>
  </div>
</template>

<script>
import Controller from "@/libs/framework/controller";
import Create from "./create";
export default class Instance extends Controller {
  onBeforeInit() {
    this.urls = {
      model: "/smartform/smartVersion/getListModel",
      query: "/smartform/smartVersion/query",
      save: "/smartform/smartVersion/save",
      delete: "/smartform/smartVersion/delete",
      entity: "/smartform/smartVersion/getEntity",
    };
  }

  mixin() {
    return {
      components: {
        Create,
      },
      data() {
        return {
          publishVisible: false,
        };
      },
      methods: {
        publish() {
          this.$refs["create"].upload();
        },
        exportVersion() {
          window.open(
            process.env.VUE_APP_BASE_API +
              "/smartform/smartVersion/export?_r=" +
              Math.random()
          );
        },
        formValidate(forms) {
          return this.$refs["create"].$refs["form1"].validate();
        },
        renderOperateType(val, row, column) {
          let find = this.super.$util.find(
            this.controlData.VersionOperateTypes,
            (item) => {
              return item.value === val;
            }
          );
          return (find || {}).key;
        },
      },
      mounted() {},
    };
  }
}
</script>

<style scoped lang="scss">
</style>

